package com.authine.cloudpivot.web.api.controller;

import com.authine.cloudpivot.web.api.controller.base.BaseController;
import com.authine.cloudpivot.web.api.service.ProfessionalService;
import com.authine.cloudpivot.web.api.vo.ResultBean;
import com.authine.cloudpivot.web.api.vo.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: ProfessionalController <br/>
 * Description: <br/>
 * date: 2020/8/25 11:25<br/>
 * @author fj<br />
 * @since JDK 1.8
 */

@Api(description = "和记黄埔相关接口", tags = "职员基础信息")
@RestController
@RequestMapping("/public/professional")
@Slf4j
@Validated
public class ProfessionalController extends BaseController {
    @Autowired
    private ProfessionalService professionalService;

    /**
     * Description: 通过webservice接口获取数据，增加或更新职员信息
     * @Param: []
     * @Author: fj
     * @Date: 2020/8/25
     * @Return: ResultBean
     */
    @ApiOperation(value = "增加或更新职员信息")
    @PostMapping("/addOrUpdateProfessional")
    public ResultBean addOrUpdateProfessional(int hours) {
        ResultBean resultBean = new ResultBean();
        int result = 0;
        result = professionalService.addOrUpdateProfessional(hours);
        if (result == ResultCode.ok) {
            resultBean.setMsg("操作成功");
        } else if (result == ResultCode.network_error) {
            resultBean.setMsg("网络异常，请稍后再试");
        } else if (result == ResultCode.insert_error) {
            resultBean.setMsg("请初始化数据信息");
        } else {
            resultBean.setMsg("操作失败，请检查数据");
        }
        resultBean.setResult(result);
        log.info("addOrUpdateProfessional end，resultBean：{}", result);
        return resultBean;
    }
}
